/**
 * Heterotopia - an up-to-date Java-based MUD system
 * Copyright (C) 2011 Bill Garrett <memesis@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package heterotopia.oa;

import java.util.Map;

import org.apache.camel.spi.Registry;
import org.apache.camel.spring.spi.ApplicationContextRegistry;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author garrett
 */
public class ObjectRegistry implements Registry, ApplicationContextAware{
	private Registry parent;
	
	public void setApplicationContext(ApplicationContext arg0) throws BeansException {
		parent = new ApplicationContextRegistry(arg0);
	}

	public ObjectRegistry() {
	}
	
	/* (non-Javadoc)
	 * @see org.apache.camel.spi.Registry#lookup(java.lang.String)
	 */
	public Object lookup(String arg0) {
		Object o = parent.lookup(arg0);
		if(o != null)
			return o;
		return null;
	}

	/* (non-Javadoc)
	 * @see org.apache.camel.spi.Registry#lookup(java.lang.String, java.lang.Class)
	 */
	public <T> T lookup(String arg0, Class<T> arg1) {
		Object o = parent.lookup(arg0, arg1);
		if(o != null)
			return (T) o;
		return null;
	}

	/* (non-Javadoc)
	 * @see org.apache.camel.spi.Registry#lookupByType(java.lang.Class)
	 */
	public <T> Map<String, T> lookupByType(Class<T> arg0) {
		return parent.lookupByType(arg0);
	}
}